﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HZ.BidSystem.Model;

namespace HZ.BidSystem.DAL
{
    public class DAL_ThreePwdConfig
    {
        public static IList<HZ.BidSystem.Model.ThreePwdConfig> GetThreePwdConfig(int projectid)
        {
            return HZ.Data.DAL_Helper.CommonFillList<ThreePwdConfig>(HZ.Data.DbHelperFactory.Create().ExecuteTable(string.Format("SELECT * FROM TB_ThreePwdConfig WHERE ProjectId = {0}", projectid)));
        }

        public static int CheckThreePwdConfig(HZ.BidSystem.Model.ThreePwdConfig threepwdconfig, string pwd)
        {
            var model = HZ.Data.DAL_Helper.GetModelByID(threepwdconfig);
            if (model == null)
            {
                return 3;
            }
            else
            {
                string pwdhash = HZ.Fun.GetMd5(pwd);
                if (string.Compare(pwdhash, model.CompeteDecPassword, true) == 0)
                {
                    return 1;
                }
                else
                {
                    return 2;
                }
            }

        }

        public static int SetThreePwdConfigCount(int projectid, int count)
        {
            ThreePwdConfig c = new ThreePwdConfig() { ProjectId = projectid };

            for (int i = 0; i < count; i++)
            {
                HZ.Data.DAL_Helper.OperateTableSQL(c, HZ.Data.TableOperator.Insert);
            }
            return 1;
        }

       
    }
}
